package com.six.work.controller;


import com.github.pagehelper.PageInfo;
import com.six.work.entity.*;
import com.six.work.services.InvitationServices;
import com.six.work.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("invitation")
public class InvitationController {
    @Autowired
    private InvitationServices invitationServices;

    @GetMapping("/list")
    public  List<Invitation> findPostByTitle(String title) {
        return invitationServices.findPostByTitle(title);
    }

    @GetMapping("/del")
    public Integer DelPostByID(@RequestParam("post_id") Integer post_id) {
        return invitationServices.DelPostByID(post_id);
    }

    @GetMapping("/find")
    public List<Invitation> findContent(Integer post_id){
        return invitationServices.findContent(post_id);
    }

    @PostMapping("/add")
    public Integer InsertInvitation(@RequestBody Invitation invitation){
        return invitationServices.insertInvitation(invitation);
    }


    @GetMapping("/update")
    public Invitation getUpdatePage(@RequestParam("post_id") Integer post_id){
        return invitationServices.SelectInvByID(post_id);
    }

    @PostMapping("/update")
    public Integer UpdateInvitation(@RequestBody Invitation invitation) {
        return invitationServices.updateInvitation(invitation);
    }

    @GetMapping("/list1/{num}") //分页查询
    public Result findAllInvitation(
            @PathVariable("num") Integer num,
            @RequestParam(value="applicant_id",defaultValue = "0") Integer applicant_id) {
        Result result = new Result();
        PageInfo<InvView> pageInfo = invitationServices.findAllInvitation(num);
        result.setObject(pageInfo);
        return result;
    }


}
